#include "DataXJsonConverter.h"

QJsonObject DataXJsonConverter::toJson(const s_PreProcess3DSPara& obj) {
    QJsonObject json;
    json["fRoiZMin"] = obj.fRoiZMin;
    json["fRoiZMax"] = obj.fRoiZMax;
    json["fRoiXMin"] = obj.fRoiXMin;
    json["fRoiXMax"] = obj.fRoiXMax;
    json["fRoiYMin"] = obj.fRoiYMin;
    json["fRoiYMax"] = obj.fRoiYMax;

    json["fThSeg0Dis"] = obj.fThSeg0Dis;
    json["iThSeg0NumPtsMin"] = obj.iThSeg0NumPtsMin;
    json["iThSeg0NumPtsMax"] = obj.iThSeg0NumPtsMax;
    json["fThSeg0DiameterMin"] = obj.fThSeg0DiameterMin;
    json["fThSeg0DiameterMax"] = obj.fThSeg0DiameterMax;

    json["bUseDisToPlane"] = obj.bUseDisToPlane;
    json["fSampleDtp"] = obj.fSampleDtp;
    json["fThSegAngleDtp"] = obj.fThSegAngleDtp;
    json["fThSegDisDtp"] = obj.fThSegDisDtp;
    json["fPtsSelToPlaneDisMin"] = obj.fPtsSelToPlaneDisMin;
    json["fPtsSelToPlaneDisMax"] = obj.fPtsSelToPlaneDisMax;
    json["fThSeg2DisDtp"] = obj.fThSeg2DisDtp;
    json["iThSeg2NumPtsMinDtp"] = obj.iThSeg2NumPtsMinDtp;
    json["iThSeg2NumPtsMaxDtp"] = obj.iThSeg2NumPtsMaxDtp;

    return json;
}

QJsonObject DataXJsonConverter::toJson(const s_DefectPlateBPara& obj) {
    QJsonObject json;
    json["fThNZAbsVal"] = obj.fThNZAbsVal;
    json["fQgOffsetL"] = obj.fQgOffsetL;
    json["fQgOffsetR"] = obj.fQgOffsetR;
    json["fQgOffsetU"] = obj.fQgOffsetU;
    json["fQgOffsetD"] = obj.fQgOffsetD;
    json["fThBulgeLowerC"] = obj.fThBulgeLowerC;
    json["fThBulgeHigerC"] = obj.fThBulgeHigerC;
    json["fThBulgeLowerS"] = obj.fThBulgeLowerS;
    json["fThBulgeHigerS"] = obj.fThBulgeHigerS;
    json["fQgThOffset"] = obj.fQgThOffset;
    json["fQgLHOrg"] = obj.fQgLHOrg;
    json["fQgLExCol"] = obj.fQgLExCol;
    json["fQgLExRow"] = obj.fQgLExRow;
    json["fQgRHOrg"] = obj.fQgRHOrg;
    json["fQgRExCol"] = obj.fQgRExCol;
    json["fQgRExRow"] = obj.fQgRExRow;
    json["fQgUHOrg"] = obj.fQgUHOrg;
    json["fQgUExCol"] = obj.fQgUExCol;
    json["fQgUExRow"] = obj.fQgUExRow;
    json["fQgDHOrg"] = obj.fQgDHOrg;
    json["fQgDExCol"] = obj.fQgDExCol;
    json["fQgDExRow"] = obj.fQgDExRow;
    json["fRenderRangeScale"] = obj.fRenderRangeScale;
    json["fConnectionDis"] = obj.fConnectionDis;

    return json;
}

QJsonObject DataXJsonConverter::toJson(const s_JggyPara& obj) {
    QJsonObject json;
    json["fDjDiamiter"] = obj.fDjDiamiter;
    json["fJgLzUpOffset"] = obj.fJgLzUpOffset;
    json["fJgDpUpOffset"] = obj.fJgDpUpOffset;
    json["iModeJgPPZStepMode"] = obj.iModeJgPPZStepMode;
    json["fJgPPZStepFix"] = obj.fJgPPZStepFix;
    json["fJgPPZStepK"] = obj.fJgPPZStepK;
    json["fJgPPZStepB"] = obj.fJgPPZStepB;
    json["fJgPPZStepMin"] = obj.fJgPPZStepMin;
    json["fJgPPZStepMax"] = obj.fJgPPZStepMax;
    json["iModeJgPPYStepMode"] = obj.iModeJgPPYStepMode;
    json["fJgPPYStepFix"] = obj.fJgPPYStepFix;
    json["fJgPPYStepK"] = obj.fJgPPYStepK;
    json["iModeJgPPSort"] = obj.iModeJgPPSort;
    json["fQgSafeDis"] = obj.fQgSafeDis;
    json["fJgTdZUp"] = obj.fJgTdZUp;
    json["fOffsetCutStartPos"] = obj.fOffsetCutStartPos;
    json["fOffsetBothEndsL"] = obj.fOffsetBothEndsL;
    json["fOffsetBothEndsR"] = obj.fOffsetBothEndsR;
    json["fOffsetPtsX"] = obj.fOffsetPtsX;
    json["fOffsetPtsY"] = obj.fOffsetPtsY;
    json["fOffsetPtsZ"] = obj.fOffsetPtsZ;

    return json;
}

QJsonObject DataXJsonConverter::toJson(const s_PoseH& obj) {
    QJsonObject json;
    json["fTransX"] = obj.fTransX;
    json["fTransY"] = obj.fTransY;
    json["fTransZ"] = obj.fTransZ;
    json["fRotX"] = obj.fRotX;
    json["fRotY"] = obj.fRotY;
    json["fRotZ"] = obj.fRotZ;
    json["dwType"] = obj.dwType;
    return json;
}

// ==================== 反序列化实现 ====================

s_PreProcess3DSPara DataXJsonConverter::fromJson_s_PreProcess3DSPara(const QJsonObject& json) {
    s_PreProcess3DSPara obj;
    obj.fRoiZMin = getDouble(json, "fRoiZMin", 0.0);
    obj.fRoiZMax = getDouble(json, "fRoiZMax", 0.0);
    obj.fRoiXMin = getDouble(json, "fRoiXMin", 0.0);
    obj.fRoiXMax = getDouble(json, "fRoiXMax", 0.0);
    obj.fRoiYMin = getDouble(json, "fRoiYMin", 0.0);
    obj.fRoiYMax = getDouble(json, "fRoiYMax", 0.0);

    obj.fThSeg0Dis = getDouble(json, "fThSeg0Dis", 0.0);
    obj.iThSeg0NumPtsMin = getInt(json, "iThSeg0NumPtsMin", 0);
    obj.iThSeg0NumPtsMax = getInt(json, "iThSeg0NumPtsMax", 0);
    obj.fThSeg0DiameterMin = getDouble(json, "fThSeg0DiameterMin", 0.0);
    obj.fThSeg0DiameterMax = getDouble(json, "fThSeg0DiameterMax", 0.0);

    obj.bUseDisToPlane = getBool(json, "bUseDisToPlane", false);
    obj.fSampleDtp = getDouble(json, "fSampleDtp", 10.0);
    obj.fThSegAngleDtp = getDouble(json, "fThSegAngleDtp", 1.5);
    obj.fThSegDisDtp = getDouble(json, "fThSegDisDtp", 10.0);
    obj.fPtsSelToPlaneDisMin = getDouble(json, "fPtsSelToPlaneDisMin", 3.0);
    obj.fPtsSelToPlaneDisMax = getDouble(json, "fPtsSelToPlaneDisMax", 100.0);
    obj.fThSeg2DisDtp = getDouble(json, "fThSeg2DisDtp", 5.0);
    obj.iThSeg2NumPtsMinDtp = getInt(json, "iThSeg2NumPtsMinDtp", 5000);
    obj.iThSeg2NumPtsMaxDtp = getInt(json, "iThSeg2NumPtsMaxDtp", 5000000);

    return obj;
}

s_DefectPlateBPara DataXJsonConverter::fromJson_s_DefectPlateBPara(const QJsonObject& json) {
    s_DefectPlateBPara obj;
    obj.fThNZAbsVal = getDouble(json, "fThNZAbsVal", 0.0);
    obj.fQgOffsetL = getDouble(json, "fQgOffsetL", 0.0);
    obj.fQgOffsetR = getDouble(json, "fQgOffsetR", 0.0);
    obj.fQgOffsetU = getDouble(json, "fQgOffsetU", 0.0);
    obj.fQgOffsetD = getDouble(json, "fQgOffsetD", 0.0);
    obj.fThBulgeLowerC = getDouble(json, "fThBulgeLowerC", 0.0);
    obj.fThBulgeHigerC = getDouble(json, "fThBulgeHigerC", 0.0);
    obj.fThBulgeLowerS = getDouble(json, "fThBulgeLowerS", 0.0);
    obj.fThBulgeHigerS = getDouble(json, "fThBulgeHigerS", 0.0);
    obj.fQgThOffset = getDouble(json, "fQgThOffset", 0.0);
    obj.fQgLHOrg = getDouble(json, "fQgLHOrg", 0.0);
    obj.fQgLExCol = getDouble(json, "fQgLExCol", 0.0);
    obj.fQgLExRow = getDouble(json, "fQgLExRow", 0.0);
    obj.fQgRHOrg = getDouble(json, "fQgRHOrg", 0.0);
    obj.fQgRExCol = getDouble(json, "fQgRExCol", 0.0);
    obj.fQgRExRow = getDouble(json, "fQgRExRow", 0.0);
    obj.fQgUHOrg = getDouble(json, "fQgUHOrg", 0.0);
    obj.fQgUExCol = getDouble(json, "fQgUExCol", 0.0);
    obj.fQgUExRow = getDouble(json, "fQgUExRow", 0.0);
    obj.fQgDHOrg = getDouble(json, "fQgDHOrg", 0.0);
    obj.fQgDExCol = getDouble(json, "fQgDExCol", 0.0);
    obj.fQgDExRow = getDouble(json, "fQgDExRow", 0.0);
    obj.fRenderRangeScale = getDouble(json, "fRenderRangeScale", 0.0);
    obj.fConnectionDis = getDouble(json, "fConnectionDis", 0.0);

    return obj;
}

s_JggyPara DataXJsonConverter::fromJson_s_JggyPara(const QJsonObject& json) {
    s_JggyPara obj;
    obj.fDjDiamiter = getDouble(json, "fDjDiamiter", 0.0);
    obj.fJgLzUpOffset = getDouble(json, "fJgLzUpOffset", 0.0);
    obj.fJgDpUpOffset = getDouble(json, "fJgDpUpOffset", 0.0);
    obj.iModeJgPPZStepMode = getInt(json, "iModeJgPPZStepMode", 0);
    obj.fJgPPZStepFix = getDouble(json, "fJgPPZStepFix", 0.0);
    obj.fJgPPZStepK = getDouble(json, "fJgPPZStepK", 0.0);
    obj.fJgPPZStepB = getDouble(json, "fJgPPZStepB", 0.0);
    obj.fJgPPZStepMin = getDouble(json, "fJgPPZStepMin", 0.0);
    obj.fJgPPZStepMax = getDouble(json, "fJgPPZStepMax", 0.0);
    obj.iModeJgPPYStepMode = getInt(json, "iModeJgPPYStepMode", 0);
    obj.fJgPPYStepFix = getDouble(json, "fJgPPYStepFix", 0.0);
    obj.fJgPPYStepK = getDouble(json, "fJgPPYStepK", 0.0);
    obj.iModeJgPPSort = getInt(json, "iModeJgPPSort", 0);
    obj.fQgSafeDis = getDouble(json, "fQgSafeDis", 0.0);
    obj.fJgTdZUp = getDouble(json, "fJgTdZUp", 0.0);
    obj.fOffsetCutStartPos = getDouble(json, "fOffsetCutStartPos", 0.0);
    obj.fOffsetBothEndsL = getDouble(json, "fOffsetBothEndsL", 0.0);
    obj.fOffsetBothEndsR = getDouble(json, "fOffsetBothEndsR", 0.0);
    obj.fOffsetPtsX = getDouble(json, "fOffsetPtsX", 0.0);
    obj.fOffsetPtsY = getDouble(json, "fOffsetPtsY", 0.0);
    obj.fOffsetPtsZ = getDouble(json, "fOffsetPtsZ", 0.0);

    return obj;
}

s_PoseH DataXJsonConverter::fromJson_s_PoseH(const QJsonObject& json) {
    s_PoseH obj;
    obj.fTransX = getDouble(json, "fTransX", 0.0);
    obj.fTransY = getDouble(json, "fTransY", 0.0);
    obj.fTransZ = getDouble(json, "fTransZ", 0.0);
    obj.fRotX = getDouble(json, "fRotX", 0.0);
    obj.fRotY = getDouble(json, "fRotY", 0.0);
    obj.fRotZ = getDouble(json, "fRotZ", 0.0);
    obj.dwType = getInt(json, "dwType", 0);
    return obj;
}
